<?php

function connettidb()
{
	require_once 'config.php';
	
	mysql_connect($db['host'],$db['userdb'],$db['password']) 
	or die('impossibile collegarsi al server');

	mysql_select_db($db['nomedb']) 
	or die('impossibile collegarsi al server');

}

function getpage($id,$lang='')
{

connettidb();
	/*$sql_it= "SELECT *,title_it AS title,content_it AS content
	         FROM pages WHERE id = $id AND status = 1";
	
	$sql_en= "SELECT *,title_en AS title,content_en AS content
	         FROM pages WHERE id = $id AND status = 1";
	if($lang=='it')
	{
		$sql=$sql_it;
	}
	else{
		$sql=$sql_en;
		}*/
	
$sql= "SELECT id,section,sub_section,status,title_$lang AS title,content_$lang AS content
	         FROM pages 
	         WHERE id = $id AND status = 1";

$result= mysql_query($sql);
	return $result;
}

function getAllpages($lang='')
{
	connettidb();	
	$sql= "SELECT id,section,sub_section,status,title_$lang AS title,content_$lang AS content
	         FROM pages WHERE status = 1 ORDER BY title ASC";

$result= mysql_query($sql);
	return $result;
}

function getAllpagesBysection($section,$lang='')
{
	connettidb();	
	$sql= "SELECT id,section,sub_section,status,title_$lang AS title,content_$lang AS content
	         FROM pages WHERE status = 1 AND section=$section ORDER BY sub_section,title";

$result= mysql_query($sql);
	return $result;
}

function getAllpagesBysubsection($section,$subsection,$lang='')
{
	connettidb();	
	$sql= "SELECT id,section,sub_section,status,title_$lang AS title,content_$lang AS content
	         FROM pages WHERE status = 1 AND section=$section AND sub_section=$subsection ORDER BY sub_section,title";

$result= mysql_query($sql);
	return $result;
}

function isCorrectSection($request)
{
	require_once 'config.php';
	return isset($sections[$request]);
}